﻿using CPF;
using CPF.Animation;
using CPF.Charts;
using CPF.Controls;
using CPF.Drawing;
using CPF.Input;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace CPFUI.IControl
{
    [CPF.Design.DesignerLoadStyle("res://$safeprojectname$/Stylesheet1.css")]//用于设计的时候加载样式
    public class MindNodeItem : Control
    {
        /// <summary>
        /// 开始拖拽时候窗体位置
        /// </summary>
        internal PixelPoint startOffset;
        /// <summary>
        /// 开始拖拽时候鼠标位置
        /// </summary>
        internal PixelPoint dragMove;
        /// <summary>
        /// 正在拖拽移动中
        /// </summary>
        [Browsable(false)]
        public bool IsDragMove
        {
            get { return GetValue<bool>(); }
            internal set { SetValue(value); }
        }
        public MindNode MindNode;
        public MindNodeItem(){
            MindNode=new MindNode();
        }
        //模板定义
        protected override void InitializeComponent()
        {
        }


#if !DesignMode //用户代码写到这里，设计器下不执行，防止设计器出错
        protected override void OnInitialized()
        {
            base.OnInitialized();
            MarginLeft = 0;
            MarginTop= 0;
        }
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Focus();
                Mouxy = e.Location;
                isclick = true;
                //(Parent as BluePrint).SelectThisInstance(this);
                CaptureMouse();
                //ZIndex = Parent.GetChildren();
            }
            base.OnMouseDown(e);
        }
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.LeftButton == MouseButtonState.Released)
            {
                isclick = false;
                ReleaseMouseCapture();
            }
        }
        private Point Mouxy;
        private bool isclick = false;
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed && isclick)
            {
                var a = e.Location - Mouxy;
                MarginLeft += a.X;
                MarginTop += a.Y;
                // TransformPoint
            }
            base.OnMouseMove(e);
        }
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
            
        }
#endif
    }
}
